package com.ssplayer.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.ssplayer.activity.R;
import com.ssplayer.bean.Video;
import com.ssplayer.utils.DownTuUtils;
import com.ssplayer.utils.MediaUtils;

public class VideoAdapter extends BaseAdapter {

	private Activity activity;
	private List<Video> videos;
	private Video video;

	public VideoAdapter() {
	}

	public VideoAdapter(Activity activity, List<Video> videos) {
		super();
		this.activity = activity;
		this.videos = videos;
	}

	@Override
	public int getCount() {
		return videos.size();
	}

	@Override
	public Object getItem(int position) {
		return videos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		VideoHolder videoHolder = null;
		if (convertView == null) {
			videoHolder = new VideoHolder();
			convertView = LayoutInflater.from(activity).inflate(
					R.layout.video_item, null);
			videoHolder.video_thumbnail = (ImageView) convertView
					.findViewById(R.id.video_thumbnail);
			videoHolder.video_title = (TextView) convertView
					.findViewById(R.id.video_title);
			videoHolder.video_duration = (TextView) convertView
					.findViewById(R.id.video_duration);
			convertView.setTag(videoHolder);
		} else {
			videoHolder = (VideoHolder) convertView.getTag();
		}
		video = videos.get(position);
		videoHolder.video_title.setText(video.getTitle());
		videoHolder.video_duration.setText(MediaUtils.formatDuration(video
				.getDuration()));
		// ImageLoader imageLoader = ImageLoader.getInstance();
		// imageLoader.init(DownTuUtils.getConfig(activity));
		// imageLoader.displayImage(videos.get(position).getUrl(),
		// videoHolder.video_thumbnail, DownTuUtils.getOptions());
		// videoHolder.video_thumbnail.setImageBitmap(MediaUtils
		//		.createVideoThumbnail(video.getUrl()));
		return convertView;
	}

	public class VideoHolder {
		private ImageView video_thumbnail;
		private TextView video_title;
		private TextView video_duration;
	}

}